#pragma once

#include <string>
using namespace std;

#include "sqlite3.h"
#include "DataPkt.h"

class SqlHelper
{
public:
	SqlHelper(void);
	~SqlHelper(void);

	bool Init(const char *dir, const char *name);

    bool InsertCont(BuyData &bd);
	bool InsertWeight(WeightList &wl);

	bool UpdateStage(int s);
	bool UpdateStatus(WeightList &wl);
	bool UpdataWeight(WeightList &wl);
	bool UpdataSort(WeightList &wl);

	bool SearchCont(BuyData &bd);
	bool SearchWList(BuyData &bd);

	bool SearchContInfoHead(DpRspContInfo &ci);
	bool SearchContInfoPlan(DpRspContInfo &ci);

	bool SaveContInfo(DpRspContInfo &ci);

	bool SortWeightTime(BuyData &bd);

	void Clear();

private:
	void CreateTable(const char *sql);

	void CreateTable();
	void CreateCurrentTable();
	void CreateContInfoHead();
    void CreateContInfoPlan();

	void DeleteBuyData();
	void DeleteContInfo();

	bool InsertContInfoHead(DpRspContInfo &ci);
	bool InsertContInfoPlan(ContPlan &cp);

private:
	sqlite3 *m_Db;
	string m_Dir;
};
